package com.atguigu.eduservice.api;


import com.atguigu.commonutils.R;
import com.atguigu.eduservice.entity.EduCourse;
import com.atguigu.eduservice.entity.EduTeacher;
import com.atguigu.eduservice.query.TeacherQuery;
import com.atguigu.eduservice.service.EduCourseService;
import com.atguigu.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 讲师 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2022-03-31
 */
@Api(description="前台名师管理")
//@CrossOrigin
@RestController
@RequestMapping("/eduservice/teacherapi")
public class TeacherApiController {

    @Autowired
    private EduTeacherService teacherService;
    @Autowired
    private EduCourseService courseService;

    @ApiOperation(value = "分页查询前台名师列表")
    @GetMapping("getTeacherApiPage/{page}/{limit}")
    public R getTeacherApiPage(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable Long page,

            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable Long limit){

        Page<EduTeacher> pageParam = new Page<>(page, limit);

        Map<String, Object> map =  teacherService.getTeacherApiPageVo(pageParam);


        return  R.ok().data(map);
    }

    @ApiOperation(value = "根据ID查询名师和主讲的课程")
    @GetMapping("getTeacherCourseById/{id}")
    public R getTeacherCourseById(
            @ApiParam(name = "id", value = "讲师ID", required = true)
            @PathVariable String id){

        EduTeacher teacher = teacherService.getById(id);

        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id", id);
        List<EduCourse> eduCourseList = courseService.list(wrapper);

        return R.ok().data("teacher", teacher).data("courseList", eduCourseList);
    }

}

